package ilearning.demo.processor;

import com.alibaba.cloud.nacos.NacosConfigProperties;
import ilearning.demo.utils.NacosConfigUtil;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author Wang Xu
 * @date 2023/11/8
 */
@Component
public class NacosConfigPropertiesPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof NacosConfigProperties) {
            NacosConfigProperties configProperties = (NacosConfigProperties)bean;
            NacosConfigUtil.setConfigService(configProperties.configServiceInstance());
        }
        return bean;
    }
}